package com.sdgakj.interviews.job20180803;

/**
 * @Author: Du Ronghong
 * @Description:
 * @Date: Created in 18:49 2018/8/14
 * @Modified By:
 */
public class StringTest {

    public static void main(String[] args) {
        String str = "123"; // 字符串转数字
        System.out.println(get(str));
    }

    private static int get(String str) {
        int sum = 0;
        if (str == null || str.length() == 0) {
            return 0;
        }
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            sum += (c - '0') * Math.pow(10, str.length() - 1 - i);
        }
        return sum;
    }

}
